<template>
  <div class="headerheader">
    <div class="headernavbar">
      <div class="header-nav">
        <ul>
          <li class="header-nav-font">
            <router-link :to="{name: 'index'}">首页</router-link>
          </li>
          <li class="header-nav-font">
            <router-link :to="{name: 'scene'}">景点</router-link>
          </li>
          <li class="header-nav-font">
            <router-link :to="{name: 'hotel'}">酒店</router-link>
          </li>
          <li class="header-nav-font">
            <a href="#">社区</a>
          </li>
          <li class="header-nav-font">
            <router-link :to="flag ? 'login' : '/person'">
              个人中心
            </router-link>
          </li>
        </ul>
      </div>
      <div class="header-nav-log" v-if="flag">
        <ul>
          <li class="login header-nav-font">
            <router-link :to="'login'">登录</router-link>
          </li>
          <li class="login header-nav-font">
            <router-link :to="'regs'">注册</router-link>
          </li>
        </ul>
      </div>
      <div class="header-nav-log" v-else>
        <ul>
          <li class="login">
            <img :src="avatar"/>
            <router-link class="persion-log" :to="'/person/saveScene'">
              {{nickname}}
            </router-link>
            <a href="javascript:void(0)" @click.prevent="logOut()">登出</a>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        flag: true,
        nickname: '',
        avatar: '',
      }
    },
    created() {
      let info = this.$store.state.userInfo
      if (info === null) {
        return
      }
      this.flag = false
      this.nickname = info.nickname
      this.avatar = info.avatar
    },
    mounted() {
    },
    methods: {
      logOut() {
        this.$axios({
          url: this.api.loginOut,
          params: {},
          method: 'post',
        }).then(res => {
          if (res.state === 0) {
            this.$store.commit('setToken', null)
            this.$store.commit('setUserInfo', null)
            this.flag = true
            this.$router.push("/")
          }
        })
      }
    }
  }
</script>

<style scoped>
  .activty {
    display: inline-block;
    background-color: #ff9d00;
    color: #fff !important;
    text-decoration: none;
    border-radius: 8px;
  }

  .activty a {
    height: 45px;
    background-color: #ff9d00;
    color: #fff !important;
    text-decoration: none;
  }

  .headerheader {
    background: #0D0922;
    text-align: center;
    margin: 0 auto;
    display: inline-block;
    height: 78px;
    width: 100%;
    min-width: 1040px;
    z-index: 2;
    left: 0px;
    top: 0px;
  }

  .headernavbar {
    margin: 0 auto;
    display: inline-block;
    height: 78px;
    position: relative;
  }

  .header-nav {
    height: 100%;
    float: left;
    position: relative;
    display: inline-block;
    vertical-align: top;
  }

  .header-nav ul {
    height: 100%;
    float: left;
    display: inline;
    padding: 0 10px 0 25px;
    color: #333;
    line-height: 58px;
    margin: 0px;
    font-size: 14px;
  }

  .header-nav-log {
    float: left;
    position: relative;
    display: inline-block;
    vertical-align: top;
  }

  .header-nav-log ul {
    float: left;
    display: inline;
    padding: 0 10px 0 25px;
    color: #333;
    line-height: 58px;
    margin: 0px;
    font-size: 14px;
  }

  .header-navbar {
    margin: 0 auto;
    display: inline-block;
    height: 60px;
    position: relative;
  }

  .headerheader li {
    list-style: none;
    float: left;
    padding: 0px 10px 0 25px;
    font-size: 14px;
    font-family: Arial, 'Lucida Grande', 'Microsoft Yahei', 'Hiragino Sans GB',
    'Hiragino Sans GB W3', SimSun, 'PingFang SC', STHeiti;
  }

  .header-nav-font a {
    width: 100%;
    height: 36px;
    line-height: 53px;
    margin-top: 17px;
    display: inline-block;
    padding: 0 16px 12px 16px;
    color: #fff;
    vertical-align: top;
    overflow: hidden;
  }

  .header-nav-font a:hover {
    color: #ff9d00;
    height: 45px;
    border-bottom: 3px solid #ff9d00;
  }


  .login a {
    color: #ff9d00;
    height: 43px;
    overflow: hidden;
    padding: 0 16px 12px 16px;
    display: inline-block;
  }

  .login img {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    display: inline-block;
  }

  .persion-log {
    display: inline-block;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(255, 255, 255, 1);
    background: initial;
    color: #ff9d00 !important;
  }
</style>
